package com.gitee.wsl.doc.prosemirror.history.ext

import com.gitee.wsl.doc.prosemirror.history.HistoryOptions
import com.gitee.wsl.doc.prosemirror.history.bean.Branch
import com.gitee.wsl.doc.prosemirror.history.bean.HistoryState
import com.gitee.wsl.doc.prosemirror.history.mustPreserveItems
import com.gitee.wsl.doc.prosemirror.state.EditorState
import com.gitee.wsl.doc.prosemirror.state.Transaction

fun HistoryState.done(state: EditorState,
                      tr: Transaction,
                      options: HistoryOptions,
                      prevRanges:List<IntRange>?,
                      composition:Int?,
                      newGroup:Boolean
):HistoryState {
    val done = done.addTransform(
        tr,
        if (newGroup) state.selection.getBookmark() else null,
        options,
        state.mustPreserveItems()
    )
    return HistoryState(
        done,
        Branch.empty,
        prevRanges,
        tr.time,
        composition ?: prevComposition
    )
}